import axios from 'axios'

export const getCategories = () => {
	return axios.get('/admin/categories')
		.then((response) => Promise.resolve(response.data.result))
}

export const addCategory = ({ name, display, parentId }) => {
	return axios.post('/admin/category', { name, display, parentId })
		.then((response) => Promise.resolve(response.data.result))
}

export const deleteCategory = (id) => {
	return axios.delete('/admin/category/' + id)
		.then((response) => Promise.resolve(response.data.result))
}


export const updataCategory = ({ id, name, display }) => {
	return axios.put('/admin/category/' + id, { name, display })
		.then((response) => Promise.resolve(response.data.result))
}

//更新排序
export const updateCategorySort = ({ id, sortType }) => {
	return axios.put('/admin/category/' + id + '/sort/' + sortType)
		.then((response) => Promise.resolve(response.data.result))
}
